package com.example.karendemoandroid;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

public class SocialFragment extends ListFragment {
	
	 String[] socialwebsite = new String[] {
	            "Google Plus",
	            "LinkedIn",           
	    };    
	    
	    int[] sociallogo = new int[]{
	    		R.drawable.gplus_logo,
	    		R.drawable.linkedin_logo,  			
	    };
	    
	    String[] socialwebinfo = new String[]{
	    	"https://plus.google.com/",
	    	"http://www.linkedin.com/",   	
	    };
	
	
	    @Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {	
			
			// Each row in the list stores websitename, webinfo and logo
	        List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();        
	        
	        for(int i=0;i<2;i++){
	        	HashMap<String, String> hm = new HashMap<String,String>();
	            hm.put("website", "Web : " + socialwebsite[i]);
	            hm.put("webinfo","URL : " + socialwebinfo[i]);
	            hm.put("logo", Integer.toString(sociallogo[i]) );            
	            aList.add(hm);        
	        }
	        
	        // Keys used in Hashmap
	        String[] from = { "logo","website","webinfo" };
	        
	        // Ids of views in listview_layout
	        int[] to = { R.id.logo,R.id.website,R.id.webinfo};        
	        
	        // Instantiating an adapter to store each items
	        // R.layout.listview_layout defines the layout of each item
	        SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.websitelistview_layout, from, to);       
			
			setListAdapter(adapter);
			
			return super.onCreateView(inflater, container, savedInstanceState);		
		}	

}
